package com.richrail.gui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import com.richrail.Depot;

public class TabbedView extends JTabbedPane
{
	private static final long serialVersionUID = 1L;
	
	private static List<Class<? extends View>> views = new ArrayList<Class<? extends View>>();
	
	private static Depot depot;
	
	public static void setDepot(Depot depot)
	{
		TabbedView.depot = depot; 
	}
	
	public static void addView(Class<? extends View> view)
	{
		views.add(view);
	}
	
	private TabbedView()
	{
		
	}
	
	@Override
	public Object clone()
	{
		return null;
	}
	
	public static TabbedView create() throws InstantiationException, IllegalAccessException
	{
		TabbedView tabbedView = new TabbedView();
		
		for (Class<? extends View> viewClass: views)
		{
			View view = viewClass.newInstance();
			depot.attachObserver(view);
			
			JScrollPane scrollPane = new JScrollPane();
			scrollPane.getVerticalScrollBar().setUnitIncrement(16);
			scrollPane.setViewportView(view.toComponent());
			
			tabbedView.addTab(view.getName(), scrollPane);
		}
		
		return tabbedView;
	}
}
